﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html class="x-admin-sm">
<head>
    <meta name="viewport" content="width=device-width" />
    <meta charset="UTF-8">
    <title>样版信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/Content/X-admin/css/font.css" rel="stylesheet" />
    <link href="~/Content/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/Content/X-admin/js/jquery.min.js"></script>
    <script src="~/Content/X-admin/js/xadmin.js"></script>
    <script src="~/Content/Scripts/System/systemFrame.js"></script>
    <script src="~/Content/Scripts/layui/layui.js"></script>
    <link href="~/Content/Scripts/layui/css/layui.css" rel="stylesheet" />
    <script src="~/Content/Scripts/System/Common.js"></script>
</head>
<body>
    <div class="layui-fluid" style="margin:5px">
        <div style="float:left">
            <div id="treeNav" class="demo-tree demo-tree-box" style="width: 200px; height: 500px; overflow: scroll;float:left;background-color:white"></div>

        </div>
        <div style="float:left;width:78%;">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5" name="qForm" id="qForm">
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="yCode" placeholder="样版编码" autocomplete="off" class="layui-input" id="yCode">
                        </div>
                        <div class="layui-inline layui-show-xs-block">

                            <input type="text" name="yName" placeholder="样版名称" autocomplete="off" class="layui-input" id="yName">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <select id="yStatus" name="yStatus" class="yStatus">
                                <option value="">选择状态</option>
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" lay-filter="sreach" id="userSearch" type="button" onclick="loadData('')"><i class="layui-icon">&#xe615;</i></button>
                        </div>
                        <input type="hidden" name="typeCode" id="typeCode" />
                    </form>
                </div>
                <div class="layui-card-header">
                    <button class="layui-btn" id="btnAdd" type="button" onclick="openWin()"><i class="layui-icon"></i>添加样版</button>
                    <button class="layui-btn" id="bgzt" type="button" onclick="sureChoose()"><i class="layui-icon">&#xe705;</i>样版出/入库</button>
                </div>
                <div class="layui-table-main" id="layui-table-main">
                    <table class="layui-hide" id="list" lay-filter="list"></table>
                </div>
                <input type="hidden" name="svalue" id="svalue" />
            </div>


        </div>
    </div>
</body>

</html>
<script type="text/html" id="barDemo">
    <a title="查看详情" href="javascript:;" lay-event="view"><i class="layui-icon">&#xe633;</i></a>
    <a title="版辊打印" href="javascript:;" lay-event="print"><i class="layui-icon">&#xe66d;</i></a>
    <a title="点击编辑" href="javascript:;" lay-event="edit"><i class="layui-icon">&#xe642;</i></a>
    <a title="点击删除" href="javascript:;" lay-event="del"><i class="layui-icon">&#xe640;</i></a>
</script>
<script>
    /**
    数据加载
    **/
    function loadData() {
        layui.use('table', function () {
            var condition = JSON.stringify(FormToJson("qForm"));
            var table = layui.table;
            table.render({
                elem: '#list'
            , cols: [[ //表头
                     { type: 'checkbox', fixed: 'left' }
                   , { field: 'yCode', title: '编码', width: 140 }
                   , { field: 'yName', title: '样板名称', width: 130 }
                   , { field: 'weizhi', title: '位置', width: 130 }
                   , { field: 'shuliang', title: '数量', width: 110 }
                     , { field: 'proCount', title: '存货个数', width: 90 }
                   , { field: 'ystatusName', title: '在库状态', width: 120 }
                   , { field: 'createtime', title: '创建时间', width: 150 }
                   , { fixed: 'right', title: '操作', width: 100, align: 'center', toolbar: '#barDemo' }
            ]], done: function (res, curr, count) {
                $("[data-field='id']").css('display', 'none');//隐藏列
                $.each(res['data'], function (i, j) {
                    if (j['yStatus'] != "ybin") {
                        TableRowColor('layui-table-main', i, '#FFF0AC');
                    }
                });
            }
           , url: '../Basis/GetDataList?condition=' + condition + "&dataType=yangbanin" //数据接口
            , skin: 'row' //表格风格
            , even: true
            , page: true //是否显示分页
            , limits: [20, 35, 50]
            , limit: 20 //每页默认显示的数量
            });
            //监听行工具事件
            table.on('tool(list)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                var data = obj.data //获得当前行数据
                    , layEvent = obj.event; //获得 lay-event 对应的值
                if (layEvent == 'edit') {
                    InfoOpenPage("../Basis/UpdateTemplate?dataId="+data.id, "样版信息", "85%", "90%");
                } else if (layEvent == 'print') {
                    SSO("yangban", data.yCode);
                }
                else if (layEvent == 'del') {
                    layer.confirm('确认要删除该数据？', function (index) {
                        $.ajax({
                            url: "../Basis/DelYangBanInfo",
                            type: "post",
                            data: { dataId: data.id },
                            success: function (data) {

                                if (data.Result) {
                                    layer.msg("删除成功");
                                } else {
                                    layer.msg("删除失败");
                                }
                                loadData();
                            }
                        });
                        layer.close(index);
                    });

                }
                else if (layEvent == 'view') {
                    OpenPage("样版详情", '../Basis/YangBanDetail?dataId=' + data.id);
                }
            });

            //监听工具条
            table.on('checkbox(list)', function (obj) {
                var data = obj.data;
                //为父窗口input赋值
                $("#svalue").val("");
                var checkStatus = table.checkStatus('list');
                var codes = "";
                for (var i = 0; i < checkStatus.data.length; i++) {
                    codes += checkStatus.data[i].yCode + ",";
                }
                $("#svalue").val(codes.substr(0, codes.length - 1));

            });
        });
    }

    var type = "";
    $(function () {
        CommonData("ybzt", "yStatus");
        leftTree();
      layui.use('form', function () {
         var form = layui.form;
       form.render();
       });
    })

    function leftTree() {
        $.ajax({
            url: "../Basis/CommonTree",
            dataType: "json",
            type: "POST",
            data: { tCode: "yb" },
            success: function (data) {
                if (data.Result) {
                    loadTree(data.Data);
                } else {
                    layer.msg(data.Message);
                }
            }
        });
    }
    /**
    类型树加载方法
    **/
    function loadTree(data) {
        var tree = layui.tree;
        var layer = layui.layer;
        var util = layui.util;
        //开启节点操作图标
        tree.render({
            elem: '#treeNav'
          , data: data
          , click: function (obj) {
              type = obj.data["id"];
              $("input[ name='typeCode']").val(type);

              loadData();
          }
        });
    }

    function openWin() {
        if (type == "") {
            layer.msg("请先选择类型"); return;
        }
        InfoOpenPage("../Basis/UpdateTemplate?type=" + type + "&dataId=0", "样版信息添加", "85%", "90%");
    }
    /**
    确认样版状态
    **/
    function sureChoose() {
        var value = $("#svalue").val();
        if (value == "") {
            layer.msg("没有选择任何数据"); return;
        } else {
            InfoOpenPage("../Basis/YangBanStatus?yCodes=" + value, "样版状态操作", "76%", "85%");
        }

    }
</script>
